package com.nf.exam.web;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.nf.exam.entity.ProductEntity;
import com.nf.exam.service.ProductService;
import com.nf.exam.util.JsonUtil;
@WebServlet("/list")
public class ProductListServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		ProductService proService=new ProductService();
//		List<ProductEntity> list=null;
//		try {
//			list=proService.getAll();
//		} catch (SQLException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		String result=null;
		try {
			result=JsonUtil.toJson(proService.getAll());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		resp.setContentType("application/json;charset=UTF-8");
		resp.getWriter().println(result);
	}

}
